#include <bits/stdc++.h>
using namespace std;

int n, a[5005], col[5005], ans;

void dfs(int step, int co) {
    if (step > n) {
        int tmp = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = i - 1; j >= 1; j--) {
                if (col[i] == col[j]) {
                    if (a[i] == a[j]) tmp += a[i];
                    break;
                }
            }
        }
        ans = max(ans, tmp);
        return;
    }
    col[step] = co;
    dfs(step + 1, 1);
    dfs(step + 1, 0);
}

signed main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T = 0;
    cin >> T;
    while (T--) {
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        ans = 0;
        dfs(0, 0);
        dfs(0, 1);
        cout << ans << '\n';
    }
    return 0;
}
//20 pts ?
